<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
require 'func.php';
require_once 'config.php';
$studentID = "120";
$attempt = "1";
$testID = "1";
$questionID = "1";
$currentQuestion = "3"; 


function drawQuestion($currentQuestion) 
{
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die ("Could not execute query");
$query = "SELECT * FROM question
WHERE questionID='$currentQuestion'";
$result = mysqli_query($con,$query) or die ("Could not execute query");
$row = mysqli_fetch_assoc($result);
extract($row);
	
echo "<div>
<h2>Question $questionID</h2>\n";
echo "<p>$stem</p>
</div>\n";
echo "<div id='resource'>$resource</div>\n<form method='POST'>";	
 
if ($type == "multiple-choice")
{
	$labels = array("option1"=>"$option1","option2"=>"$option2","option3"=>"$option3","option4"=>"$option4");

foreach($labels as $field => $label)
{
	echo "<div class='field'>
	<label for='$field'>$label</label>
	<input type='radio' name='$field' id='$field'
	value='$row[$field]'  /></div>\n";
}		
}
 



if ($type == "checkbox")
{

	$labels = array("option1"=>"$option1","option2"=>"$option2","option3"=>"$option3","option4"=>"$option4");
foreach($labels as $field => $label)
{
	echo "<input type='checkbox' name='$field' id='$field'
	value='$row[$field]'  />$row[$field]<br />\n";
	
}
}
 
if ($type == "true-false")
{
	$labels = array("option1"=>"$option1","option2"=>"$option2");

foreach($labels as $field => $label)
{
	echo "<div class='field'>
	<label for='$field'>$label</label>
	<input type='radio' name='$field' id='$field'
	value='$row[$field]'  />
</div>\n";

} 
}
echo "<input type='hidden' name='getFeedback' value='TRUE' /><div id='submit'><input type='submit' 
value='Check Answer' id='getFeedback'/>\n";
echo "</div>\n</form>\n</body>\n</html>";
}

$drawQuestion = drawQuestion($currentQuestion);
if (isset($_POST['getFeedback'])) {
$currentQuestion++;
	echo "<form method='POST'><input type='hidden' name='getNext' value='TRUE' /><input type='submit' 
value='get next' id='getNextBtn'/></form>";
}
if (isset($_POST['getNext'])) {
drawQuestion($currentQuestion++);
}

?>